import { defineStore } from "pinia";
import  request  from "@/utils/request";
import type {ApiRes , HeadItem} from '@/types/data'
// 默认的头部分类
const topCategory = [
  '居家',
  '美食',
  '服饰',
  '母婴',
  '个护',
  '严选',
  '数码',
  '运动',
  '杂项',
]
const defaultList = topCategory.map((item, index) => {
  return {
    name: item,
  }
})

export default defineStore('home',{
  state:()=>({
    money:100,
    categoryList:defaultList as HeadItem[]
  }),
  actions:{
    //获取头部
    async getAllCategory(){
      const res = await request.get<ApiRes<HeadItem[]>>('/home/category/head')
      console.log('res',res);
      this.categoryList = res.data.result
    }
  }
})